package com.itheima.springbootwebbtalis.controller;

import com.itheima.springbootwebbtalis.pojo.PageResult;
import com.itheima.springbootwebbtalis.pojo.Result;
import com.itheima.springbootwebbtalis.pojo.Student;
import com.itheima.springbootwebbtalis.pojo.StudentQueryParam;
import com.itheima.springbootwebbtalis.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    // 分页查询
    @GetMapping
    public Result page(StudentQueryParam param){
        log.info("分页查询参数：{}",param);
        PageResult pageResult =studentService.page(param);
        return Result.success(pageResult);
    }
   // 添加学员
    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.add(student);
        return Result.success();
    }
    // 根据id查询学员
    @GetMapping("/{id}")
    public Result showById(@PathVariable Integer id){
        Student student=studentService.showById(id);
        return Result.success(student);
    }

   // 修改学员
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }


     // 批量删除学员
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.deleteById(ids);
        return Result.success();
    }
    // 违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id ,@PathVariable short score ){
        studentService.violation(id,score);
        return Result.success();
    }
}
